using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class NewsMsgPluginSetCtrl : PluginSettingBaseCtrl
	{
		private bool mFlagAccountStatusChanged;
		private bool initState;
		internal Grid LayoutRoot;
		internal ClickableLayout btnViewNews;
		internal MMToggleSwitch toggleReceiveNews;
		internal ClickableLayout btnClearNews;
		private bool _contentLoaded;
		public NewsMsgPluginSetCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.NewsMsgPluginSetCtrl_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.DoFinish));
		}
		public override void Exit()
		{
			base.Exit();
		}
		public void NewsMsgPluginSetCtrl_Loaded(object sender, RoutedEventArgs e)
		{
			this.InitUI();
		}
		public void DoFinish(object sender, RoutedEventArgs e)
		{
			if (this.mFlagAccountStatusChanged)
			{
				ServiceCenter.sceneNewSync.doScene(1, syncScene.MM_NEWSYNC_SCENE_OTHER);
				this.mFlagAccountStatusChanged = false;
			}
		}
		private void InitUI()
		{
			OnToggleStateChanged onToggleStateChanged = new OnToggleStateChanged(this.checkedStateChanged);
			this.toggleReceiveNews.onToggleStateChanged = onToggleStateChanged;
			this.toggleReceiveNews.Text = strings.Plugin_news_receive;
			Account curAccount = AccountMgr.getCurAccount();
			if (curAccount != null)
			{
				this.toggleReceiveNews.IsChecked = !AccountMgr.disableRecommendTXNewsToMe;
				this.initState = true;
			}
			this.btnClearNews.set_Visibility(0);
		}
		private void checkedStateChanged(object sender, bool isCheckOn)
		{
			if (this.initState && sender == this.toggleReceiveNews)
			{
				AccountMgr.disableRecommendTXNewsToMe = !isCheckOn;
				this.mFlagAccountStatusChanged = true;
			}
		}
		private void checkedOn(object sender, EventArgs e)
		{
			this.checkedStateChanged(sender, true);
		}
		private void checkedOff(object sender, EventArgs e)
		{
			this.checkedStateChanged(sender, false);
		}
		private void btnViewMessages_Click(object sender, RoutedEventArgs e)
		{
			ToolFunction.GotoPageForUserControl("/Source/Plugin/TXNews/UI/NewsSessionView.xaml", null, false);
			for (int i = 0; i < PageManager.getInstance().basePageList.get_Count(); i++)
			{
				if (PageManager.getInstance().basePageList.get_Item(i) is NewsSessionView)
				{
					PageManager.getInstance().PopPage();
					return;
				}
			}
		}
		private void UninstallBtn_Click(object sender, RoutedEventArgs e)
		{
		}
		private void btnClearNews_Click(object sender, RoutedEventArgs e)
		{
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Plugin_news_clear, null, true, strings.COM_Confirm, strings.COM_Cancel);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.OnClearNewsMsgHandler);
		}
		private void OnClearNewsMsgHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				NewsMgr.NewsMsgClearAll();
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/TXNews/UI/NewsPluginSetCtrl.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.btnViewNews = (ClickableLayout)base.FindName("btnViewNews");
			this.toggleReceiveNews = (MMToggleSwitch)base.FindName("toggleReceiveNews");
			this.btnClearNews = (ClickableLayout)base.FindName("btnClearNews");
		}
	}
}
